package ru.pb.game.network.engine.client.packets.receivable;

import ru.pb.game.network.clients.GameClient;
import ru.pb.game.network.engine.client.packets.FromClientToGameServerPacket;
import ru.pb.game.network.engine.client.packets.sendable.PROTOCOL_BASE_USER_ENTER_ACK;

public class PROTOCOL_BASE_USER_ENTER_REQ extends FromClientToGameServerPacket
{
	private int _accSize;
	private String _account;
	private long _UNK_LONG;
	private int _oneByte;
	private byte[] _IP;

	public PROTOCOL_BASE_USER_ENTER_REQ()
	{}

	@Override
	public void readImpl()
	{
		readH();
		_accSize = readC(); // Размер аккаунта
		_account = readS(_accSize); // Аккаунт

		_UNK_LONG = readQ(); // Постоянно 132343 -> Ставится в ЛС, тут PROTOCOL_BASE_LOGIN_ACK
		_oneByte = readC(); // Постоянно 1
		_IP = readB(4); // Айпишник.
	}

	@Override
	public void runImpl()
	{
		GameClient client = getClient();
		if(client != null)
		{
			getClient().setAccount(_account);
			getClient().restorePlayer(_account);
			getClient().setLocalIp(_IP);
			client.sendPacket(new PROTOCOL_BASE_USER_ENTER_ACK());
		}
	}
}